package business;

import java.util.ArrayList;
import java.util.List;

import dao.ICommentDAO;
import dao.JDBCCommentDAO;
import domain.Comment;
import domain.User;

public class BusinessComment {

	public static List<Comment> getAllComments() {
		ICommentDAO comentarioDAO= new JDBCCommentDAO();
		return comentarioDAO.getAllComments();
	}
	
	public static List<Comment> getAllCommentsByUser(String loginUser){
		ICommentDAO comentarioDAO= new JDBCCommentDAO();
		return comentarioDAO.getAllCommentsByUser(loginUser);
	}
	
	public static List<Comment> getAllCommentsByVideo(Integer idVideo) {
		ICommentDAO comentarioDAO= new JDBCCommentDAO();
		return comentarioDAO.getAllCommentsByVideo(idVideo);
	}
	
	public static Comment getCommentsById(Integer idComment) {
		ICommentDAO comentarioDAO= new JDBCCommentDAO();
		return comentarioDAO.getCommentsById(idComment);
	}	
	
	public static Comment getLastComentByUser(Integer UserId){
		ICommentDAO comentarioDAO = new JDBCCommentDAO();
		return comentarioDAO.getLastComentByUser(UserId);
	}
	
	public static List<Comment> getAllCommentsByVideoAndUser(Integer idVideo,Integer idUser){
		User user= BusinessUser.getUserById(idUser);
		List<Comment> result=new ArrayList<Comment>();
		List<Comment> comments= BusinessComment.getAllCommentsByVideo(idVideo);
		List<String> friends= new ArrayList<String>();
		for(Integer idFriend:user.getFriends()){
			friends.add(BusinessUser.getLoginById(idFriend));
		}
		for(Comment c:comments){
			if(friends.contains(c.getLoginUser())||c.getLoginUser().equals(user.getLogin())){
				result.add(c);
			}
		}
		return result;
	}
	
	public static void insertComment(Integer idVideo, Integer idUser, String comentario){
		ICommentDAO comentarioDAO = new JDBCCommentDAO();
		comentarioDAO.insertComment(idVideo, idUser, comentario);
	}
}	